//验证表单
validate(
    {
        'User[name]':{'required':true},
        'User[password]':{'required':true},
        'User[phone]':{'required':true}, 
        'User[email]':{'required':true,'email':true},
        'User[birthday]':{'required':true},
        'User[identity_num]':{'required':true},
        'User[role]':{'required':true},
    },
    {
        'User[name]':{'required':'登录名不能为空'},
        'User[password]':{'required':'密码不能为空'},
        'User[phone]':{'required':'号码不能为空'},
        'User[email]':{'required':'邮箱不能为空','email':'请输入正确邮箱格式'},
        'User[birthday]':{'required':'生日不能为空'},
        'User[identity_num]':{'required':'身份证号码不能为空'},
        'User[role]':{'required':'用户角色不能为空'},
    }
);

//用户详情链接
$('.user_detail').click(function(){
	var user_id = $(this).attr('data-id');
    var index = layer.load(0, {shade: false});
	// alert(user_id);
	location.href = '?r=user/userinfo/detail&user_id='+user_id;
});

//办理离职
$('.leave').click(function(){
	var user_id = $(this).attr('data-id'),
		url = '?r=user/userinfo/leave',
		index = $(this).parent().parent().parent().index();
	layer.confirm('确认办理离职吗?',{btn:['确定','取消']},function(){
		$.ajax({
			url:url,
			data:{'user_id':user_id},
			dataType:'json',
			type:'get',
			success:function(data){
				if(data.code == 200){
					$('.userleave').eq(index).find('.sureleave').text(data.time);
					$('.userleave').eq(index).find('.leave').remove();
					layer.closeAll();
				}else{
					layer.msg('失败了,看看哪里错了吧!');
				}
			}

		})
		
	})
	// alert(user_id);
});

//viewer图片查看器
$('.viewer').viewer();

